<?php
/**
 * 后台首页
 */
namespace Admin\Controller;

use Common\Controller\AdminbaseController;

class ShimingrenzhengController extends AdminbaseController {

     //实名认证  列表
    function shiming_lst(){
        $nickname = trim(I("nickname"));
        $shenfenzheng_num = trim(I("shenfenzheng_num"));
        $stime = I("time1");
        $etime = I("time2");

        $p = I("p");
        $where = " 1 ";
        if(!empty($nickname)){
            $where .= " and nickname like '%{$nickname}%' ";
        }
        if(!empty($shenfenzheng_num)){
            $where .= " and shenfenzheng like '%{$shenfenzheng_num}%' ";
        }

        $time1 = strtotime($stime);

        $time2 = strtotime($etime);
        if (!empty($time1)) {
            $where .= " and {$time1} <= renzheng_times";
        }
        if (!empty($time2)) {
            $where .= " and renzheng_times <= {$time2}";
        }

        $count =  M("account")->where($where . " and is_renzheng=1")->count();
        if($count==0){
            $p = 0;
        }else{
            if(empty($p)){
                $p = 1;
            }
        }
        $totalpage = ceil($count/10);
        $page = $this->page($count,10);
        $sd = ($p-1)*10;

        $data = M("account")
            ->where($where . " and is_renzheng=1")
            ->limit($page->firstRow . ',' . $page->listRows)
            ->order("id desc")
            ->select();

//        echo M()->getLastSql() ;die;
        $this->assign("data",$data);
        $this->assign("nickname",$nickname);
        $this->assign("shenfenzheng_num",$shenfenzheng_num);
        $this->assign("time1",$stime);
        $this->assign("time2",$etime);
        $this->assign("page", $page->show('Admin'));
        $this->assign("p",$p);
        $this->assign("sd",$sd);
        $this->assign("totalpage",$totalpage);
        $this->display();
    }
     //实名认证 查看详细
    function shiming_xiangxi(){
        $id = I("id");
        $data = M("account")->where("id = $id")->find();
        $this->assign("data",$data);
        $this->assign("id",$id);
        $this->display();
    }
    //取消认证
    function shiming_quxiao(){
        $id = I("id");
        $phone= I("phone");
        $nickname= I("nickname");
        $return = $this->app_short_message($phone,$nickname);
        if ($return) {
            $dat['shenfenzheng_photo'] = "";
            $dat['is_renzheng'] = 0;
            $dat['renzheng_times'] = 0;
            $dat['shenfenzheng'] = "";
            $dat['name'] = "";
            $da = M("account")->where("id = $id")->save($dat);
            if($da){
                $this->success("取消成功",U("Shimingrenzheng/shiming_lst"));
            }
        } else {
              $this->success("取消失败",U("Shimingrenzheng/shiming_xiangxi"));
        }
    }
    /*
     * 取消验证  短信发送模块
     * */
    function app_short_message($phone, $nickname){
        require_once "./public/duanxin/api_demo/SmsDemo.php";
        ini_set('date.timezone', 'Asia/Shanghai');
        $demo = new \SmsDemo();
        $response = $demo->sendSms(
            "{$phone}", // 短信接收者
            "SMS_121906095", // 短信模板编号
            Array(  // 短信模板中字段的值
                "name" => "{$nickname}",
            )
        );
        $response = (array)$response;
        if ($response['Code'] == "OK") {
            return true;
        } else {
            return false;
        }
    }





















}

